# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Contributor: Martell Malone <martellmalone@gmail.com>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Mainntainer: Duncan Bellamy <dunk@denkimushi.com>
pkgname=py3-numpy1
pkgver=1.26.4
pkgrel=0
pkgdesc="Scientific tools for Python"
url="https://www.numpy.org/"
arch="all"
license="BSD-3-Clause"
options="!check"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	cython
	gfortran
	libbsd-dev
	openblas-dev
	py3-gpep517
	py3-meson-python
	py3-nose
	py3-setuptools
	py3-wheel
	python3-dev
	"
depends="!py3-numpy"
subpackages="
	$pkgname-dev
	$pkgname-tests
	$pkgname-pyc
	$pkgname-f2py::noarch
	"
source="https://github.com/numpy/numpy/releases/download/v$pkgver/numpy-$pkgver.tar.gz
	numpy-1.17.0-musl.patch
	s390x-hwcap.patch
	site.cfg"
builddir="$srcdir/numpy-$pkgver"

export Atlas=None
# numpy is a huge library (~26 MiB) optimized for performance, so compiling
# with -Os to sacrifice performance for ~1 MiB doesn't make sense.
export CFLAGS="${CFLAGS/-Os/-O3} -flto=auto"
export CXXFLAGS="${CXXFLAGS/-Os/-O3} -flto=auto"

prepare() {
	default_prepare
	cp "$srcdir"/site.cfg "$builddir"/
}

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

f2py() {
	pkgdesc="f2py for numpy1 (for python3)"
	depends="py3-numpy1=$pkgver-r$pkgrel python3-dev"
	install_if="$pkgname-f2py=$pkgver-r$pkgrel python3"

	amove usr/bin/f2py*
}

tests() {
	find "$pkgdir" -name tests -type d | while read -r p; do
		amove "${p#"$pkgdir"}"
	done
}

sha512sums="
f7121ab4099fa0686f9c095d456baa4a5869d651d7b7a06385f885f329cf08f11024b5df5e7b4ee705970062a8102ec4f709512eabbfd5c9fccce4ef83b9c208  numpy-1.26.4.tar.gz
a66a953408dc4f1a9763eaf64ad0400696581c70551c457f0c773aa34bd3de0b21b239484270c08227b6ba60fc1e605c94245ba9279df452d6ec9bf94c8eacfb  numpy-1.17.0-musl.patch
cf353102400ecd45e611f7fc7e6a576b7eddf4b27979dd54501a5fcc4d9a301b105de66ef6b44a97e649436a40117ed28deb7a4668a3e7a01216b3d139ca7fc0  s390x-hwcap.patch
3540b5a37a8ea1a09001e1627bee53cf847800f67a24214636f18be43e20a080b0de97ce1036db2ea05e166fd302cc137d632967c443ae422f7dce6dca67c264  site.cfg
"
